//
//  HNSH_AddressEditFooterView.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/26.
//

#import "HNSH_AddressEditFooterView.h"

@interface HNSH_AddressEditFooterView ()
/**  */
@property (nonatomic, strong)UIView * bgView;
/**  */
@property (nonatomic, strong)UILabel * titleLabel;
/**  */
@property (nonatomic, strong)UILabel * desLabel;
/**  */
@property (nonatomic, strong)UISwitch * switchView;
@end

@implementation HNSH_AddressEditFooterView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor appBGColor];
        [self addAllViews];
        [self addAllLayout];
    }
    return self;
}

//MARK: Myself Methods
- (void)addAllViews{
    self.backgroundColor = [UIColor clearColor];
    [self addSubview:self.bgView];
    [self.bgView addSubview:self.titleLabel];
    [self.bgView addSubview:self.desLabel];
    [self.bgView addSubview:self.switchView];
}

- (void)addAllLayout{
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(10);
        make.bottom.mas_equalTo(0);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.mas_equalTo(17);
        make.height.mas_equalTo(22);
    }];
    [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleLabel);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(4);
        make.height.mas_equalTo(20);
    }];
    [self.switchView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-30);
        make.width.mas_equalTo(37);
        make.height.mas_equalTo(20);
        make.centerY.mas_equalTo(0);
    }];
}

- (BOOL)getDefaultStatus{
    return self.switchView.isOn;
}

//MARK: Setter Methods
- (void)setIsDefault:(BOOL)isDefault{
    _isDefault = isDefault;
    
    self.switchView.on = isDefault;
}

//MARK: Getter Methods
- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [UIView new];
        _bgView.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
    }
    return _bgView;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.font = [UIFont systemFontOfSize:16];
        _titleLabel.textColor = [UIColor appBlack333LabelColor];
        _titleLabel.text = @"设为默认";
    }
    return _titleLabel;
}

- (UILabel *)desLabel{
    if (!_desLabel) {
        _desLabel = [UILabel new];
        _desLabel.font = [UIFont systemFontOfSize:14];
        _desLabel.textColor = [UIColor colorWithHexString:@"#999999"];
        _desLabel.text = @"提醒：每次下单时会使用该地址";
    }
    return _desLabel;
}

- (UISwitch *)switchView{
    if (!_switchView) {
        _switchView = [UISwitch new];
    }
    return _switchView;
}

@end
